<?php 
$re = "/add/";
$str = uri_string();
if (preg_match($re, $str)) {
    $sub = TRUE;
} else {
    $sub = FALSE;
}
?>
<div class="title-menu">
    <h2><?php if($sub==TRUE) echo "Thêm danh mục"; else echo "Sửa danh mục";?></h2>
</div>
<nav class="bonus">
    <a href="<?php echo base_url("backend/categories");?>"><< Quay lại</a>
</nav>
<article>
    <form method="post" action="">
        <fieldset>
            <ul class="error">
                <?php echo validation_errors(); ?>                       
            </ul>
            
            <p>
                <label>Tên danh mục:</label>
                <input type="text" name="data[name]" value="<?php echo isset($cat->name)?$cat->name:'';?>"/>
            </p>
            <p>
                <label>Danh mục cha:</label>
                <select name="data[pid]">
                    <option value="0">Mới</option>
                    <?php 
                    if(isset($parcat) && count($parcat))
                        foreach ($parcat as $pc){
                    ?>
                    <option value="<?php echo $pc->id;?>" <?php
                    if(isset($cat->pid) && $cat->pid != 0 ){
                        if($cat->pid === $pc->id)
                            echo 'selected';
                    }
                    ?>><?php echo $pc->name;?></option>
                    <?php
                    }
                    ?>
                </select>
            </p>
            <p>
                <label></label>
                <input type="submit" name="add" value="<?php if($sub == TRUE)echo "Thêm"; else echo "Sửa";?>"/>
            </p>
        </fieldset>
    </form>
</article>